package com.gdk.ksoft.ui.customers.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.gdk.ksoft.ui.customers.models.AddrInfoModel;

import java.util.List;

/**
 * Created by hel on 2014-12-22.
 * 客户收货地址数据适配器
 */
public class CustomerAddrAdapter extends BaseAdapter{

    private List<AddrInfoModel> list;
    private Context context ;

    public CustomerAddrAdapter(Context context,List<AddrInfoModel> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final AddrInfoModel item = list.get(position);
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_pnewdeliveraddr_lstaddress,null);
            holder.txtAddr = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtAddress);
            holder.txtAbbr = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtAbbreviation);
            holder.txtType = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtCustomerType);
            holder.txtArea = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtCustomerArea);
            holder.txtContractor = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtCustomerName);
            holder.txtConnectity = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtCustomerConnectity);
            holder.txtManageArea = (TextView)convertView.findViewById(R.id.item_pnewdeliverAddr_lstaddress_txtManagementArea);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        holder.txtAddr.setText(item.addr);
        holder.txtAbbr.setText(item.abbr);
        holder.txtType.setText(item.ctype);
        holder.txtArea.setText(item.carea);
        holder.txtContractor.setText(item.contractor);
        holder.txtConnectity.setText(item.connectity);
        holder.txtManageArea.setText(item.addrArea);
        return convertView;
    }

    class ViewHolder{
        public TextView txtAddr;
        public TextView txtAbbr;
        public TextView txtType;
        public TextView txtArea;
        public TextView txtContractor;
        public TextView txtConnectity;
        public TextView txtManageArea;
    }

}
